<?php
session_start();
//包含头
include '../PHP/head.php';
?>
<?php
//包含bootstrap的顶端按钮
include '../PHP/menu.php';
?>

<br />
<br />
<p class="text-center lead">模块报价项目通知</p>
<?php
if(isset($_GET['project_id'])) {
	//查询编号信息
	require_once ('../FNS/db_fns.php');
	
	$project_id = $_GET['project_id'];
	
	//数据过滤和处理

	if (! get_magic_quotes_gpc()) {
	$project_id=addslashes ($project_id);
	}
	
	$db = db_connect();
	$query="select projects.code as project_code, projects.name as project_name, projects.sale as sale_id, projects.entrust_date, users.name as sale_name from projects inner join users on projects.sale = users.id where projects.id = '".$project_id."'";
	
	$result=$db->query ($query);
	$num_result=$result->num_rows;
	
	//拿出数据
	$row=$result->fetch_assoc ();
	$project_code = stripslashes ($row['project_code']);
	$project_name = stripslashes ($row['project_name']);
	$sale_name = stripslashes ($row['sale_name']);
	$sale_id = stripslashes ($row['sale_id']);

	
	$result->free();
	
	//列出编号基本信息
	echo "
		<br />
		<div class='row'>
			<div class='col-md-2'><p class='text-right'>报价编号：</p></div>
			<div class='col-md-2'><p>".$project_code."</p></div>
			<div class='col-md-2'><p class='text-right'>项目名称：</p></div>
			<div class='col-md-4'><p>".$project_name."</p></div>
			<div class='col-md-1'><p class='text-right'>销售：</p></div>
			<div class='col-md-1'><p>".$sale_name."</p></div>
		</div>
		<br />
	";
	
	

	
	echo "
	
	<form class='form-horizontal' role='form' action = '../PHP/note_project.php' method = 'post'>
		<input type='hidden' name = 'project_id' value = '".$project_id."'>
		<div class='form-group'>
				<label for='ei' class='col-md-2 control-label'>电仪：</label>
				<div class='col-md-4'>
					<select class='form-control' name='ei'>
						<option value = 'none'>不需要报价</option>";
	
	//把专业负责人搜出来
	$query="select * from users where position = 'LEI'";
	$result=$db->query ($query);
	$num_result=$result->num_rows;
	
	//循环输出数据
	
	for ($i=0; $i < $num_result; $i++) {

	$row=$result->fetch_assoc ();
	
	$leader_id = stripslashes ($row['id']);
	$leader_name = stripslashes ($row['name']);
	
	echo "<option value = '".$leader_id."'>".$leader_name."</option>";
	
	}
	$result->free();
	
	echo "	
					</select>
				</div>
		</div>
		<div class='form-group'>
			<label for='proposal_ei' class='col-md-2 control-label'>标书要求：</label>
			<div class='col-md-10'>
				<textarea class='form-control' rows='2' name='proposal_ei'></textarea>
			</div>
		</div>
		<div class='form-group'>
				<label for='st' class='col-md-2 control-label'>结构：</label>
				<div class='col-md-4'>
					<select class='form-control' name='st'>
						<option value = 'none'>不需要报价</option>";
	//把专业负责人搜出来
	$query="select * from users where position = 'LST'";
	$result=$db->query ($query);
	$num_result=$result->num_rows;
	
	//循环输出数据
	
	for ($i=0; $i < $num_result; $i++) {

	$row=$result->fetch_assoc ();
	
	$leader_id = stripslashes ($row['id']);
	$leader_name = stripslashes ($row['name']);
	
	echo "<option value = '".$leader_id."'>".$leader_name."</option>";
	
	}
	$result->free();
	
	echo "	
					</select>
				</div>
		</div>
		<div class='form-group'>
			<label for='proposal_st' class='col-md-2 control-label'>标书要求：</label>
			<div class='col-md-10'>
				<textarea class='form-control' rows='2' name='proposal_st'></textarea>
			</div>
		</div>
		<div class='form-group'>
				<label for='pi' class='col-md-2 control-label'>管道：</label>
				<div class='col-md-4'>
					<select class='form-control' name='pi'>
						<option value = 'none'>不需要报价</option>";
	//把专业负责人搜出来
	$query="select * from users where position = 'LPI'";
	$result=$db->query ($query);
	$num_result=$result->num_rows;
	
	//循环输出数据
	
	for ($i=0; $i < $num_result; $i++) {

	$row=$result->fetch_assoc ();
	
	$leader_id = stripslashes ($row['id']);
	$leader_name = stripslashes ($row['name']);
	
	echo "<option value = '".$leader_id."'>".$leader_name."</option>";
	
	}
	$result->free();
	
	echo "	
					</select>
				</div>
		</div>
		<div class='form-group'>
			<label for='proposal_pi' class='col-md-2 control-label'>标书要求：</label>
			<div class='col-md-10'>
				<textarea class='form-control' rows='2' name='proposal_pi'></textarea>
			</div>
		</div>
		<div class='form-group'>
				<label for='ve' class='col-md-2 control-label'>容器：</label>
				<div class='col-md-4'>
					<select class='form-control' name='ve'>
						<option value = 'none'>不需要报价</option>";
	//把专业负责人搜出来
	$query="select * from users where position = 'LVE'";
	$result=$db->query ($query);
	$num_result=$result->num_rows;
	
	//循环输出数据
	
	for ($i=0; $i < $num_result; $i++) {

	$row=$result->fetch_assoc ();
	
	$leader_id = stripslashes ($row['id']);
	$leader_name = stripslashes ($row['name']);
	
	echo "<option value = '".$leader_id."'>".$leader_name."</option>";
	
	}
	$result->free();
	
	echo "	
					</select>
				</div>
		</div>
		<div class='form-group'>
			<label for='proposal_ve' class='col-md-2 control-label'>标书要求：</label>
			<div class='col-md-10'>
				<textarea class='form-control' rows='2' name='proposal_ve'></textarea>
			</div>
		</div>
		<div class='form-group'>
				<label for='me' class='col-md-2 control-label'>机械：</label>
				<div class='col-md-4'>
					<select class='form-control' name='me'>
						<option value = 'none'>不需要报价</option>";
					
	//把专业负责人搜出来
	$query="select * from users where position = 'LME'";
	$result=$db->query ($query);
	$num_result=$result->num_rows;
	
	//循环输出数据
	
	for ($i=0; $i < $num_result; $i++) {

	$row=$result->fetch_assoc ();
	
	$leader_id = stripslashes ($row['id']);
	$leader_name = stripslashes ($row['name']);
	
	echo "<option value = '".$leader_id."'>".$leader_name."</option>";
	
	}
	$result->free();
	$db->close();
	echo "	
					</select>
				</div>
		</div>
		<div class='form-group'>
			<label for='proposal_me' class='col-md-2 control-label'>标书要求：</label>
			<div class='col-md-10'>
				<textarea class='form-control' rows='2' name='proposal_me'></textarea>
			</div>
		</div>";

	
	echo "
		<br />
		<div class='form-group'>
			<div class='col-md-offset-2 col-md-3'>
				<input class='btn btn-success' type = 'submit' value='发布通知'/>
			</div>
		</div>
	</form>
	
	";

}

if (isset($_POST['project_id'])) {
	
	require_once ('../FNS/db_fns.php');
	
	$project_id = trim($_POST['project_id']);
	$ei = trim($_POST['ei']);
	$ei_p = trim($_POST['proposal_ei']);
	$pi = trim($_POST['pi']);
	$pi_p = trim($_POST['proposal_pi']);
	$st = trim($_POST['st']);
	$st_p = trim($_POST['proposal_st']);
	$ve = trim($_POST['ve']);
	$ve_p = trim($_POST['proposal_ve']);
	$me = trim($_POST['me']);
	$me_p = trim($_POST['proposal_me']);
		
	//数据过滤和处理
	//加引号避免输入数据库出错
	if (! get_magic_quotes_gpc()) {	
	$project_id = addslashes ($project_id);
	$ei = addslashes ($ei);
	$ei_p = addslashes ($ei_p);
	$st = addslashes ($st);
	$st_p = addslashes ($st_p);
	$pi = addslashes ($pi);
	$pi_p = addslashes ($pi_p);
	$ve = addslashes ($ve);
	$ve_p = addslashes ($ve_p);
	$me = addslashes ($me);
	$me_p = addslashes ($me_p);
	}
	
	$note_date = date('Y-m-d');
	
	//各专业flag
	$ei_flag = 0;
	$st_flag = 0;
	$pi_flag = 0;
	$ve_flag = 0;
	$me_flag = 0;
	if ($ei<>"none") {$ei_flag = 1;}
	if ($st<>"none") {$st_flag = 1;}
	if ($pi<>"none") {$pi_flag = 1;}
	if ($ve<>"none") {$ve_flag = 1;}
	if ($me<>"none") {$me_flag = 1;}
	
	//连接数据库并插入数据

	$db= db_connect();

	$query="update projects set ei = '".$ei."', ei_p = '".$ei_p."', st = '".$st."', st_p = '".$st_p."', pi = '".$pi."', pi_p = '".$pi_p."', ve = '".$ve."', ve_p = '".$ve_p."', me = '".$me."', me_p = '".$me_p."', flag_del = '3', ei_flag = '".$ei_flag."', pi_flag = '".$pi_flag."', st_flag = '".$st_flag."', ve_flag = '".$ve_flag."', me_flag = '".$me_flag."', note_date = '".$note_date."' where id = '".$project_id."'";
	$result=$db->query ($query);
	if ($result){
		echo "<br />";
		echo "修改成功，请查询已发布报价通知。";
	}else{
	echo "<br />";
	echo"修改失败，请重新查询已下委托项目！";
	echo $entrust_date;
	
	$db->close();
	
	}
	
	
	
	}





?>


</div>
</body>
</html>
